import HttpUtils from '../HttpUtils/HttpUtils';

Page({
  ...HttpUtils.func,
  data: {
    pageIndex:1,
    pageItems:15,
    totalPages:0,
    newsItems:[]

  },
  onLoad() {
    this.loadNoticeList();
  },
  loadNoticeList:function(){
    var params="{'message': {'body': {'news': {'pageIndex': "+this.data.pageIndex+",'pageItems': "+this.data.pageItems+",'partyId': "+getApp().globalData.partyId+",'userId': "+getApp().globalData.userId+",}},'header': {'action': 'REQUEST','command': 'PARTY_NOTICE_LIST','sequence': '10000000001'},'version': '1.0'}}";
    this.httpGet(getApp().globalData.dangjianUrl,params,"通知公告列表加载失败").then(
      (respData)=>{
        var result=respData.data.message.body.result.code;
        if(1==result){
          var newsItems=respData.data.message.body.newsItems;
          var totalPages=newsItems.totalPages;
          newsItems=newsItems.news;
          this.setData({
            "newsItems":newsItems,
            "totalPages":totalPages
          });
        }else{
          this.showPageMsg("alert", respData.data.result.description)        }
      }
    ); 
  },
  onReachBottom:function(e){
    var pageIndex=this.data.pageIndex+1;
    var totalPages=this.data.totalPages;
    if(totalPages>=pageIndex){
      this.setData({
        "pageIndex":pageIndex
      });
      this.loadNoticeList();      
    }else{
      this.showPageMsg("tips","没有更多数据了");
    }
  },
  onPullDownRefresh:function(e) {   
    this.setData({
      pageIndex:1,
      newsItems:[]
    });
    this.loadNoticeList();
    dd.stopPullDownRefresh();
  }
});
